<?php
/**
* @version $Id: category.class.php 3484 2008-02-07 09:11:27Z Radek Suski $
* @package: Sigsiu Online Business Index 2
* ===================================================
* @author
* Name: Sigrid & Radek Suski, Sigsiu.NET
* Email: sobi@sigsiu.net
* Url: http://www.sigsiu.net
* ===================================================
* @copyright Copyright (C) 2007 Sigsiu.NET (http://www.sigsiu.net). All rights reserved.
* @license see http://www.gnu.org/licenses/lgpl.html GNU/LGPL.
* You can use, redistribute this file and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*/
/*
 * no direct access
 */
defined( '_SOBI2_' ) || ( trigger_error("Restricted access", E_USER_ERROR) && exit() );
class sobi2Category {
	var $catid 				= null;
	var $name 				= null;
	var $image 				= null;
	var $image_position 	= null;
	var $description		= null;
	var $introtext			= null;
	var $published			= null;
	var $ordering			= null;
	var $count				= null;
	var $icon				= null;
	var $params				= null;
	var $myParents			= array();
	var $myChildren			= array();

	function sobi2Category($cid = 0)
	{
		$config =& sobi2Config::getInstance();
    	if( $cid ) {
			$this->catid = $cid;
			$this->getCategory($this->catid);
		}
    	if(count($config->S2_plugins)) {
    		foreach($config->S2_plugins as $plugin) {
				if(method_exists($plugin, "onCreateCategoryObj")) {
					$plugin->onCreateCategoryObj( $this );
    			}
    		}
    	}
    }
    function getCategory()
    {
    	$config =& sobi2Config::getInstance();
		$database = &$config->getDb();
    	$category = null;
    	$query = "SELECT * FROM `#__sobi2_categories` WHERE `catid` = {$this->catid} LIMIT 1";
    	$database->setQuery( $query );
    	$database->loadObject($category);
		if ($database->getErrorNum()) {
			trigger_error("sobi2category::getCategory(): DB reports: ".$database->stderr(), E_USER_WARNING);
		}
    	if( $category ) {
    		$this->name = $config->getSobiStr($category->name);
    		$this->image = $category->image;
    		$this->image_position = $category->image_position;
    		$this->description = $config->getSobiStr($category->description);
    		$this->introtext = $config->getSobiStr($category->introtext);
    		$this->ordering = $category->ordering;
    		$this->count = $category->count;
    		$this->icon = $category->icon;
    		$this->params = $config->iniToArr( $category->params );
    	}
//    	if( $config->cacheL3Enabled && ( (microtime(true) - $config->timeStart) < $config->key( "general", "add_ops_time_limit", 0.5 ) )  ) {
//    		$config->getChildCats( $this->catid, $this->myChildren );
//    		$config->getParentCats( $this->catid, $this->myParents );
//    		$config->sobiCache->addObj( get_object_vars( $this ), 0, 0, $this->catid );
//    	}
    }
    function countVisit()
    {
    	$config =& sobi2Config::getInstance();
		$database = &$config->getDb();
		$statement = "UPDATE `#__sobi2_categories` SET `count` = count + 1 WHERE `catid` = {$this->catid} LIMIT 1 ";
		$database->setQuery($statement);
		$database->query();
		if ($database->getErrorNum()) {
			trigger_error("sobi2category::countVisit(): DB reports: ".$database->stderr(), E_USER_WARNING);
		}
    }
}
?>